package com.platform.core.web.controller;

import com.platform.core.service.SysDataStandardBiz;
import com.platform.dto.SysDataStandardDto;
import com.platform.comm.web.results.DataJsonResult;
import com.platform.comm.web.results.JsonResult;
import com.platform.comm.web.results.PageListJsonResult;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;

import static com.platform.core.web.controller.BaseController.getPageable;

/**
 * Description: ncloud_sys_data_standard-管理接口
 *
 * @author Coder
 */
@RestController
@RequestMapping(name = "ncloud_sys_data_standard管理", path = "/management/ncloudSysDataStandard")
public class SysDataStandardController{

    private final SysDataStandardBiz sysDataStandardBiz;

    @Autowired
    public SysDataStandardController(SysDataStandardBiz sysDataStandardBiz) {
        this.sysDataStandardBiz = sysDataStandardBiz;
    }

    /**
     * 分页查询ncloud_sys_data_standard数据
     */
    @PostMapping(name = "查询ncloud_sys_data_standard列表", path = "/search")
    public PageListJsonResult<SysDataStandardDto> search(@RequestBody Map<String, String> map) {
        return sysDataStandardBiz.search(map, getPageable(map));
    }

    /**
    * 查询ncloud_sys_data_standard明细数据
    */
    @PostMapping(name = "查询ncloud_sys_data_standard明细", path = "/detail")
    public DataJsonResult<SysDataStandardDto> detail(@RequestBody Map<String, String> map) {
        return DataJsonResult.succeed(sysDataStandardBiz.detail(map.get("id")));
    }

    /**
    * 新增ncloud_sys_data_standard
    */
    @PostMapping(name = "新增ncloud_sys_data_standard", path = "/create")
    public JsonResult create(@RequestBody SysDataStandardDto req) {
        sysDataStandardBiz.add(req);
        return JsonResult.success();
    }

    /**
    * 修改ncloud_sys_data_standard数据
    */
    @PostMapping(name = "修改ncloud_sys_data_standard", path = "/modify")
    public JsonResult modifyNcloudSysDataStandard(@RequestBody SysDataStandardDto req) {
        sysDataStandardBiz.modify(req);
        return JsonResult.success();
    }

    /**
    * 删除ncloud_sys_data_standard
    */
    @PostMapping(name = "删除ncloud_sys_data_standard", path = "/remove")
    public JsonResult remove(@RequestBody SysDataStandardDto dto) {
        sysDataStandardBiz.remove(dto.getId());
        return JsonResult.success();
    }

    @PostMapping(name = "检查规范编码", path = "checkCodeExists")
    public DataJsonResult<Long> checkCodeExists(@RequestBody Map<String, String> map) {
        String id = Objects.toString(map.get("id"), Strings.EMPTY);
        String code = Objects.toString(map.get("code"), Strings.EMPTY);
        String type = Objects.toString(map.get("type"), Strings.EMPTY);
        return DataJsonResult.succeed(sysDataStandardBiz.validCode(id,code,type));
    }

    @PostMapping(name = "检查字规范名称", path = "checkNameExists")
    public DataJsonResult<Long> checkNameExists(@RequestBody Map<String, String> map) {
        String id = Objects.toString(map.get("id"), Strings.EMPTY);
        String name = Objects.toString(map.get("name"), Strings.EMPTY);
        String type = Objects.toString(map.get("type"), Strings.EMPTY);
        return DataJsonResult.succeed(sysDataStandardBiz.validName(id,name,type));
    }
}
